<?php

namespace App\Http\Controllers\Admin;

use DB;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class ReviewController extends Controller
{


    public function insert(Request $request)
    {
        $data=$request->only(['id','gid','content','token']);
            //处理token
            $data['token']=str_random(50);
          
           

            // dd($data);
            //执行数据插入操作
            $res = DB::table('shop_review')->insert($data);

            if($res){
                //成功 到列表页
                return redirect('/admin/review/index')->with('success','用户添加成功');
            }else{
                return back()->with('error','用户添加失败');
            }
            //dd($request->all());
        
    }
    
  
     public function getIndex(Request $request)
        {   
            //获取每页显示几条
            $num = $request->input('num',10);
            //判断是否有查询条件
            if($request->input('keywords')){
                $goods = DB::table('shop_review')->where('title','like','%'.$request->input('keywords').'%')->paginate($num);
            }else{
                $goods = DB::table('shop_review')->paginate($num);
            }

            //获取参数列表
            $list = $request->all();

           //给分页拿参数
           // return view('Admin.user.index',['users'=>$users,'list'=>$list]);
            //$cates=CateController::getCates();
            //解析模板 根目录为resources下的views
            return view('admin.review.index',['review'=>$goods,'list'=>$list]);
        }
}
